;;; Code:
;; company
(use-package company
  :ensure t
  :defer 3
  :hook
  (prog-mode . company-mode)
  (org-mode . company-mode)
  :config
  (setq company-minimum-prefix-length 1) ; 只需敲 1 个字母就开始进行自动补全
  (setq company-tooltip-align-annotations t)
  (setq company-idle-delay 0.0)
  (setq company-show-quick-access t) ;; 给选项编号 (按快捷键 M-1、M-2 等等来进行选择).
  (setq company-selection-wrap-around t)
  (setq company-transformers '(company-sort-by-occurrence))) ; 根据选择的频率进行排序

(defun moon/return-cancel-completion ()
  "Cancel completion and return."
  (interactive)
  (company-abort)
  (newline nil t))
(global-set-key (kbd "S-<return>") #'moon/return-cancel-completion)

;;; 代码补全
(use-package eglot
  :ensure t
  :hook
  (c-mode . eglot-ensure))

;;; 语法检查
(use-package flycheck
  :defer
  :ensure t
  :hook
  (c-mode . flycheck-mode)
  (emacs-lisp-mode . flycheck-mode))

;;; debug
(use-package realgud
  :defer t
  :disabled t
  :ensure t)

; tabnine补全
;(use-package company-tabnine
;  :ensure nil
;  :defer t
;  :init (add-to-list 'company-backends #'company-tabnine))

(use-package yasnippet
  :ensure t
  :hook
  (prog-mode . yas-minor-mode)
  :config
  (defun company-mode/backend-with-yas (backend)
    (append (if (consp backend) backend (list backend))
	    '(:with company-yasnippet)))
  (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
  (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
  (yas-global-mode 1)) ;; or M-x yas-reload-all if you've started YASnippet already.


(provide 'init-complement)
